package com.heima.schedule.feign;

import com.heima.apis.schedule.IScheduleClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.schedule.dtos.Task;
import com.heima.schedule.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ScheduleClient implements IScheduleClient {

    @Autowired
    private TaskService taskService;
    /**
     * 添加任务
     * @return
     */
    @PostMapping("/api/v1/schedule/add")
    public ResponseResult addTask(@RequestBody Task task){
        return ResponseResult.okResult(taskService.addTask(task));
    }

    /**
     * 取消任务
     * @param taskId
     * @return
     */
    @GetMapping("/api/v1/schedule/cancel/{taskId}")
    public ResponseResult cancelTask(@PathVariable("taskId") long taskId){
        return ResponseResult.okResult(taskService.cancelTask(taskId));
    }

    /**
     * 拉取任务
     * @param taskType  任务类型
     * @param priority  任务优先级
     * @return
     */
    @GetMapping("/api/v1/schedule/poll/{taskType}/{priority}")
    public ResponseResult poll(@PathVariable("taskType") int taskType,@PathVariable("priority") int priority){
        return ResponseResult.okResult(taskService.poll(taskType,priority));
    }
}
